// ****************************************************************
// Copyright 2012, Stephan Burguchev
// e-mail: me@sburg.net
// ****************************************************************
// *
using System;
using System.IO;

namespace Updater.Tests
{
    public class TempDirectory : IDisposable
    {
        public TempDirectory()
        {
            this.Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), '{' + Guid.NewGuid().ToString("D") + '}');
            if (Directory.Exists(this.Path))
            {
                Directory.Delete(this.Path, true);
            }

            Directory.CreateDirectory(this.Path);
        }

        public string Path { get; private set; }

        public static implicit operator string(TempDirectory value)
        {
            return value.Path;
        }

        public void Dispose()
        {
            try
            {
                Directory.Delete(this.Path, true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
